#ifndef _ADU_FLOW_H_
#define _ADU_FLOW_H_

#include "cocos2d.h"
#include "ADUConstant.h"
#include "ADUConfig.h"
#include "ADUGameManager.h"
#include "ADUParticleEmitter.h"
USING_NS_CC;

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
class Flow : public Node, public BlendProtocol {
#else
class Flow : public Node {
#endif

public:
		Flow(Node* _layer, Vec2 _position);
		~Flow();
		void 		 	initPhysics();
		void 		 	update(float dt, bool emit);
        void            updateEmittedParticle();
		void 			resetSpeed();
		void 		 	updatePosition(Vec2& _pos) ;
		void		 	createFaucet();
        void            DestroyParticle(int index);

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
		virtual void 	draw(Renderer *renderer, const Mat4 &transform, uint32_t transformFlags) override;
	    void 		 	onDraw(const Mat4 &transform, uint32_t transformFlags);
    	const BlendFunc& getBlendFunc() const override;
	    void 		 	setBlendFunc(const cocos2d::BlendFunc &var) override;
		bool 		 	initShader(b2ParticleSystem* particleSystem, float ratio);
		void 		 	setup();	
		RenderTexture*  getRenderTexture() { return mRenderTexture;}
#endif
		void 		 	setStartPosition(Vec2& _pos);
		Vec2 		 	getStartPosition();
        void            setOffset(Vec2 _offset);
		RadialEmitter*	mEmitter;
private:

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
		CustomCommand 				mCustomCommand;
    	cocos2d::Mat4 				mRatioTransform;
    	BlendFunc 					mBlendFunc;
	    Texture2D *					mTexture;
	    RenderTexture *				mRenderTexture;

#endif
	    Node*						mLayer;
	    float 						mRatio;
    	GLfloat * 					mSizes;
		b2ParticleSystem *			mParticleSystem;
		b2World *					mWorld;
		ParticleLifetimeRandomizer 	mLifetimeRandomizer;
        Vec2                        mOriginPos;
		Vec2						mPosition;
        Vec2						mOffset;
};

#endif
